package com.colin.datamove.jobscheduler;

import com.colin.datamove.job.MoveJob;
import com.colin.datamove.service.MoveService;
import com.colin.datamove.util.ThreadPool;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

import javax.annotation.Resource;

@Configuration
@EnableScheduling
public class JobScheduler {

    @Value("${epd.datamove.default.pmc}")
    private int defaultPmc;

    @Resource
    private MoveService assetCompanyService;
    @Resource
    private MoveService assetDepartmentService;
    @Resource
    private MoveService assetUserService;
    @Resource
    private MoveService assetDepartmentUserService;
    @Resource
    private MoveService openAccountService;
    @Resource
    private MoveService outAccountService;

    /**
     * 公司表迁移任务定时器
     */
    @Scheduled(cron = "0 0/1 16 * * ?")
    public void companyJobSchedule() {
        ThreadPool.putThread(new MoveJob(assetCompanyService, defaultPmc));
    }

    /**
     * 部门表迁移任务定时器
     */
    @Scheduled(cron = "0 0/1 16 * * ?")
    public void departmentJobSchedule() {
        ThreadPool.putThread(new MoveJob(assetDepartmentService, defaultPmc));
    }

    /**
     * 用户表迁移任务定时器
     */
    @Scheduled(cron = "0 0/1 16 * * ?")
    public void assetUserJobSchedule() {
        ThreadPool.putThread(new MoveJob(assetUserService, defaultPmc));
    }

    /**
     * 用户表迁移任务定时器
     */
    @Scheduled(cron = "0 0/1 16 * * ?")
    public void assetDepartmentUserJobSchedule() {
        ThreadPool.putThread(new MoveJob(assetDepartmentUserService, defaultPmc));
    }

    /**
     * 对外账户表迁移任务定时器
     */
    @Scheduled(cron = "0 0 15 * * ?")
    public void openAccountJobSchedule() {
        ThreadPool.putThread(new MoveJob(openAccountService, defaultPmc));
    }

    /**
     * 对外账户表迁移任务定时器
     */
    @Scheduled(cron = "0 0/1 17 * * ?")
    public void outAccountJobSchedule() {
        ThreadPool.putThread(new MoveJob(outAccountService, defaultPmc));
    }

}
